﻿
using System;
namespace Codemonk.Pease.Server
{
    /// <summary>
    /// 切面监视器
    /// </summary>
    /// <typeparam name="C">上下文</typeparam>
    public interface IAspectMonitor<C>
    {
        /// <summary>
        /// 方法执行前执行,可以拦截方法执行
        /// </summary>
        /// <param name="methodName">方法名称</param>
        /// <param name="context">上下文</param>
        /// <param name="instance">执行的对象</param>
        /// <param name="entity">方法传入的实体</param>
        /// <param name="backType">方法返回的类型</param>
        /// <param name="replacer">替代方法的执行结果,如果调用了此函数,则终止方法的执行,为了减少等待时间,此方法必须同步执行</param>
        void BeforeInvoke(string methodName, C context, object instance, object entity, Type backType, Action<object> replacer);
        /// <summary>
        /// 方法执行后执行
        /// </summary>
        /// <param name="methodName">方法名称</param>
        /// <param name="context">上下文</param>
        /// <param name="intance">执行的对象</param>
        /// <param name="entity">方法传入的实体</param>
        /// <param name="backvalue">方法的返回值</param>
        /// <param name="backType">方法返回的类型</param>
        /// <param name="replacer">如果调用了此函数,则返回这个替代结果,为了减少等待时间,此方法必须同步执行</param>
        void AfterInvoke(string methodName, C context, object intance, object entity, object backvalue, Type backType, Action<object> replacer);
        /// <summary>
        /// 环绕方法,捕获方法执行的异常
        /// </summary>
        /// <param name="methodName">方法名称</param>
        /// <param name="context">上下文</param>
        /// <param name="instance">执行的对象</param>
        /// <param name="entity">方法传入的实体</param>
        /// <param name="backType">方法返回的类型</param>
        /// <param name="exception">异常</param>
        /// <param name="replacer">如果调用了此函数,则返回这个替代结果,为了减少等待时间,此方法必须同步执行</param>
        void CatchException(string methodName, C context, object instance, object entity, Type backType, Exception exception, Action<object> replacer);
    }
}
